<?php

namespace app\adminmini\service;

use app\adminmini\model\MeituanOrder;
use think\facade\Db;

class TrillorderService extends BaseService
{
    public function __construct()
    {
        $this->model = new MeituanOrder();
    }

    public function getList()
    {
        $param = request()->param();
        $map = [];
        $map[] = ['o.store_id', '=', $this->userId()];


        $list = Db::name('mini_user_coupon')
            ->alias('o')
            ->join('coupon c', 'c.id=o.coupon_id')
            ->join('member u', 'u.id=o.user_id')->field('o.*,c.title,u.nickname,u.mobile')
            ->where($map)
            ->whereIn('o.type', ['2','3'])
            ->order('create_time desc')->page(PAGE, PERPAGE)
            ->select();

        $count = Db::name('mini_user_coupon')
            ->alias('o')
            ->join('coupon c', 'c.id=o.coupon_id')
            ->join('member u', 'u.id=o.user_id')->field('o.*,u.nickname,u.mobile')
            ->where($map)
            ->whereIn('o.type', ['2','3'])
            ->count();

        //返回结果
        $message = array(
            "msg" => '操作成功',
            "code" => 0,
            "data" => $list,
            "count" => $count,
        );
        return $message;
    }
}